//
//  CommonDefine.h
//  LBBase
//
//  Created by Gary on 15/6/30.
//  Copyright (c) 2015年 Lebo. All rights reserved.
//

#ifndef CommonDefine_h
#define CommonDefine_h

#import "ConfigDefine.h"

#pragma mark - Build flag

//arc编译方式，默认开启
#ifndef COMPILE_ARC_MODE
#define COMPILE_ARC_MODE
#endif

//工程是否使用swift
#ifndef BUILD_USE_SWIFT
#define BUILD_USE_SWIFT
#endif

//在此开启或关闭swift
#undef BUILD_USE_SWIFT

#ifdef BUILD_USE_SWIFT
#import <UIKit/UIKit.h>
#import "LBBase-Swift.h"
#else
#import "AppDelegate.h"
#endif

#pragma mark - 日志相关

#import <CocoaLumberjack/DDLog.h>
#ifdef DEBUG
static DDLogLevel ddLogLevel = DDLogLevelVerbose;
#else
//static const int ddLogLevel = DDLogLevelWarning;
static DDLogLevel ddLogLevel = DDLogLevelInfo;
//static const int ddLogLevel = DDLogLevelVerbose;
#endif

#define LogDebug DDLogDebug
#define LogInfo DDLogInfo
#define LogWarn DDLogWarn
#define LogError DDLogError
#define LogFunc LogInfo(@"%s", __func__)
#define LogDebugFunc LogDebug(@"%s", __func__)

#pragma mark - 文件系统相关

//资源文件目录
#define kResourceDirectory      [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Resource"]
//默认文档目录
#define kDocumentsDirectory     [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) lastObject]
//日志文件目录
//#define kLogfilesDirectory      [kDocumentsDirectory stringByAppendingPathComponent:@"Log"]
//所有用户目录
#define kUserDirectory          [kDocumentsDirectory stringByAppendingPathComponent:@"Users"]
//当前用户目录
#define kCurrentUserDirectory   [kUserDirectory stringByAppendingPathComponent:[Common currentUserID]]
#define kUserDownloadDirectory  [kCurrentUserDirectory stringByAppendingPathComponent:@"Download"]
#define kUserUploadDirectory    [kCurrentUserDirectory stringByAppendingPathComponent:@"Upload"]

//数据库文件名和文件路径
#define kDatabaseFileName       @"app.db"
#define kDatabaseFilePath       [kDocumentsDirectory stringByAppendingPathComponent:kDatabaseFileName]

#pragma mark - 系统版本相关

typedef enum ESystemVersion {
    ESystemVersion6OrLess = 1,
    ESystemVersion7,
    ESystemVersion8OrGreater,
} ESystemVersion;

typedef enum EScreenScaleType {
    EScreenScaleIPhone4,        //iPhone4，及iPhone4以前手机
    EScreenScaleIPhone5,        //iPhone5，5S的屏幕
    EScreenScaleIPhone6,        //iPhone6的屏幕
    EScreenScaleIPhone6P,       //iPhone6+的屏幕
    EScreenScaleIPad,           //EScreenScaleIPad的屏幕
} EScreenScaleType;

#pragma mark - APP本地化的信息

//在[[NSUserDefaults standardUserDefaults] objectForKey:(NSString *)]使用的KEY
//格式为前缀"kUSKey" + 带语意的后缀

#define kUSKeyAppIsFirstRun                     @"AppIsFirstRun"
#define kUSKeyBaseServerURL                     @"BaseServerURL"
#define kUSKeyCurrentUserInfo                   @"CurrentUserInfo"
#define kUSKeyCurrentToken                      @"CurrentToken"
#define kUSKeyCurrentUserID                     @"CurrentUserID"

#pragma mark - 默认的初始化值

#define kEmptyString                            @""//空字符串
#define kIntegerInvalid                         -1
#define kIntegerZero                            0
#define kIntegerOne                             1
#define kPerformDelay                           0.1f
#define kReuserIdentifier                       @"reuserIdentifier"
#define kAppCallUrlSchemeKey                    @"scheme"
#define kDescription                            @"description"

#pragma mark - 网络请求用参数名

#define kNetworkRequestTimeoutInterval          60.f                //网络请求的超时时间
#define kNetworkRequestNMIndex                  @"reqNMIndex"       //网络请求的指定的LBNetworkManager的序列号，用于短时间内的并发，最小值为0，最大值为kNMArrayCount
#define kNetworkRequestName                     @"reqName"          //网络请求的主要凭据，用于返回和重试的识别
#define kNetworkRequestUrl                      @"reqUrl"           //网络请求指定的url，如果存在该参数，将不用使用默认的url
#define kNetworkRequestData                     @"reqData"          //网络请求的数据参数
#define kNetworkResponseData                    @"rspData"          //网络返回的数据参数
#define kNetworkRequestInfo                     @"reqInfo"          //网络请求的附加信息，内容由请求方定制，用来区别返回时的用途
#define kNetworkRequestSender                   @"reqSender"        //网络请求的发送者
#define kNetworkResponseErrorMessageKey         @"errMessage"       //网络请求返回NSError时，NSError结构的errMessage字段
#define kNetworkUploadArray                     @"uploadArr"        //上传文件的列表
#define kNetworkUploadFileData                  @"uploadFileData"   //上传文件的内容的指针
#define kNetworkUploadParam                     @"uploadParam"      //上传文件的参数名
#define kNetworkUploadFileName                  @"uploadFileName"   //上传文件的文件名
#define kNetworkUploadFileType                  @"uploadFileType"   //上传文件的文件类型

#pragma mark - 网络返回数据用宏定制

//#define kNetworkResponseMessageKey           @"msg"                  //网络返回数据包中信息的关键字
#define kNetworkResponseMessageKey           @"resultMessage"           //网络返回数据包中信息的关键字
#define kNetworkResponseRetcodeKey           @"resultCode"              //网络返回数据包中返回码的关键字
#define kNetworkResponseRetdataKey           @"resultData"              //网络返回数据包中返回的数据体
#define kNetworkResponseRetcodeSucc          NetworkResponseCodeSucc    //成功返回码的值
#define kNetworkResponseUnknownError         [Common getLocalStr:@"UnknownError"]        //未知的异常错误

#pragma mark - 常见网络返回错误信息

#define kNetworkResponseErrMessage404        @"Request failed: not found (404)"
#define kNetworkResponseResultCode404        404

#pragma mark - Global UI相关

//暂时没用到，时代的眼泪
#define kGlobalBoldFontName                  @"HelveticaNeue-Bold"
#define kGlobalRegularFontName               @"HelveticaNeue"

#define kGlobalTitleFont                     [UIFont boldSystemFontOfSize:20]
#define kGlobalBartintColor                  [UIColor clearColor]
#define kGlobalTintColor                     [UIColor whiteColor]
#define kGlobalTitleTextForeGroundColor      [UIColor whiteColor]

#pragma mark - 屏幕旋转

#define DefaultAutorotateOrientations  \
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { \
    return UIInterfaceOrientationPortrait;  \
}  \
\
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {  \
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;  \
}  \
\
- (BOOL)shouldAutorotate {  \
    return YES;  \
}

#pragma mark - 工具宏

#define IsEmpty(object) (!object || ((id<NSObject>)object == [NSNull null]))      //判断对象是否为空
#define LocalStr(stringKey) [Common getLocalStr:stringKey]
#define CAlert [CustomerAlert sharedInstance]

//打印各种类型的值
#define ObjectStr(object) [NSString stringWithFormat:@"%@", object]
#define IntStr(number) [NSString stringWithFormat:@"%d", number]
#define FloatStr(number) [NSString stringWithFormat:@"%f", number]
#define ClassStr(object) NSStringFromClass(object.class)

//获取非空的值，提供默认
#define StrNonNull(str) (!IsEmpty(str) ? (str) : kEmptyString)
#define NumNonNull(num) (!IsEmpty(num) ? (num) : @(kIntegerZero))
#define ArrNonNull(arr) (!IsEmpty(arr) ? (arr) : @[])
#define DicNonNull(dic) (!IsEmpty(dic) ? (dic) : @{})

#pragma mark - 视图相关

//Rect简化宏
#define MakeRect(x, y, width, height) CGRectMake(x, y, width, height)
#define ViewWidth(view) CGRectGetWidth((view).frame)
#define ViewHeight(view) CGRectGetHeight((view).frame)

// 获取视图右边位置
#define ViewRight(view) (view.frame.origin.x + view.frame.size.width)
// 获取视图下边位置
#define ViewBottom(view) (view.frame.origin.y + view.frame.size.height)

//获取屏幕 宽度、高度
#define ScreenWidth ([UIScreen mainScreen].bounds.size.width)
#define ScreenHeight ([UIScreen mainScreen].bounds.size.height)

// the value to use if the width is unknown
#define kUnknownWidth   16777215.0f
// the value to use if the height is unknown
#define kUnknownHeight  16777215.0f

#define kNavigationBarHeight        64.f            //导航栏默认高度
#define kBottomBarHeight            49.f            //底部栏默认高度
#define kTableCellHeight            44.f            //UITableViewCell的默认高度
#define kNavigationBarIconHeight    35.f            //导航栏按钮默认高度
#define kToastHeightAboveBottom     100.f           //Toast底部栏高度

#define kMaskBackgroundColor        [UIColor grayColor] //默认灰底背景色
#define kMaskAlpha                  0.7f //默认灰底背景透明度
#define kLabelHeightDefault         21.f            //默认的UILabel控件的高度
#define kSeperatorLineThickness     0.5f            //分割线粗细
#define kSeperatorLineColor         [UIColor lightGrayColor]           //分割线颜色
#define kSubviewMarginHorizontal    15.f //子视图内的默认水平外间距

//获取颜色
#define MakeColor(r, g, b) [UIColor colorWithRed:(r) / 255.f green:(g) / 255.f blue:(b) / 255.f alpha:1.f]

#define HEXCOLOR(c)          [UIColor colorWithRed:((c>>16)&0xFF)/255.0f  \
green:((c>>8)&0xFF)/255.0f \
blue:(c&0xFF)/255.0f alpha:1.0f]

//获取字体
#define MakeFont(size) [UIFont systemFontOfSize:(size)]
#define MakeFontBold(size) [UIFont boldSystemFontOfSize:(size)]

#pragma mark - 自定义Navigation Bar相关

#define kNavigartionTitleFont                   [UIFont boldSystemFontOfSize:18.f]
#define kNavigartionBarBgColor                  [UIColor colorWithRed:17.f / 255.f green:79.f/255.f blue:192.f/255.f alpha:1.f]
#define kNavigartionBarBtnWidth                 44.f
#define kNavigartionBarBtnHeight                44.f

//Navigation Bar位置和高度
#define kNavigationBtnMarginHorizontal          5.f
#define kNavigationBtnMarginVertical            10.f
#define kNavigationBtnHeight                    (self.navigationController.navigationBar.frame.size.height - 2 * kNavigationBtnMarginHorizontal)

//自定义Navigation Bar左右按钮的view tag
#define kNavigationBarLeftBtnTag                1000
#define kNavigationBarRightBtnTag               1001

//自定义Navigation Bar按钮样式NSDictionary部分参数设置的key

//按钮样式风格
#define kNavigationBarBtnStyleKey                   @"style"        //用于在NSDictionary中的key
#define kNavigationBarBtnStyleText                  @"text"         //纯文字
#define kNavigationBarBtnStyleImage                 @"image"        //纯图片
#define kNavigationBarBtnStyleTextImage             @"text&image"   //文字和图片
#define kNavigationBarBtnStyleCustomer              @"customer"     //自定义

//按钮标题，内容为NSString*类型，在风格为text和text&image时有效
#define kNavigationBarBtnTitleKey                   @"title"

//按钮背景颜色，内容为UIImageView*或NSDictionary*, 在风格为image和text&image时有效
#define kNavigationBarBtnBackgroundImagesKey        @"backgroundImages"

//按钮正常状态和点击状态时的背景颜色，内容为UIImageView*
#define kNavigationBarBtnBackgroundImagesNormalKey  @"normal"
#define kNavigationBarBtnBackgroundImagesClickedKey @"clicked"

//按钮响应事件，设置按钮的点击事件
#define kNavigationBarBtnTargetKey                  @"target"
#define kNavigationBarBtnActionKey                  @"action"

#pragma mark - 业务相关

//数据列表加载方式
#define kTableViewLoadTypeKey                       @"loadType"
#define kTableViewLoadTypeNew                       @"loadNew"
#define kTableViewLoadTypeMore                      @"loadMore"

#endif
